package com.gexin.common.job;

import com.gexin.common.AppGlobal;
import com.gexin.model.product.Products;
import com.jfinal.log.Log;

import java.util.List;

/**
 * 预售商品的的定时器
 * 黎峻
 */
public class ProductsJob implements Runnable {
	static Log log = Log.getLog(ProductsJob.class);
	
	public void run() {
		if(AppGlobal.dev_Mode){
			log.info("执行预售商品定时器......");
		}
		StartProducts();
		EndProducts();
	}

	//检查开始
	public static void  StartProducts(){
		List<Products> list =Products.dao.find("select * from t_products where attr_type=2 and preordain_state = 0 and  DATE_FORMAT(preordain_start_time,'%Y-%m-%d %H:%i:%S') <= DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%S') ");
		for(Products activity:list){
			activity.setPreordainState(1);
			activity.update();
		}
	}

	//检查结束
	public static void  EndProducts(){
		List<Products> list =Products.dao.find("select * from t_products where attr_type=2 and preordain_state = 1 and DATE_FORMAT(preordain_end_time,'%Y-%m-%d %H:%i:%S') <= DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%S') ");
		for(Products activity:list){
			activity.setPreordainState(2);
			activity.update();
		}
	}

}
